<?php
class UserManageAction extends Action{
    
    public function userManage(){    	
    	$this->assign("validateMenuJuri",true);
        //global $cookieTools;
        //$qiaoba = $cookieTools->getCookie('qiaoba');
        //$this->smarty->assign("qiaoba",$qiaoba);
        //smartyDisplay($this->smarty,'/manage/page/systemmanage/systemusermanage/userManage.html');
    	$this->assign("smarty",'/manage/page/systemmanage/systemusermanage/userManage.html');
        
        return $this->SMARTY;
    }
    
    public function queryUserInfo(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	
    	//收集当前传入的当前页信息
    	if($params['page']!=null)
    		$currentPage = $params['page'];
    	else
    		$currentPage =1;
    	//收集当前传入的一页多少条信息
    	if($params['rows']!=null)
    		$countPage = $params['rows'];
    	else
    		$countPage =10;
    	$sysUserPage = new SysUserPage();
    	$pageInfo = $sysUserPage->initPage($params, $countPage, $currentPage);
    	$rows = $sysUserPage->getCurPageData();
    	
    	$this->assign("total",$pageInfo['countRow']);
    	$this->assign("rows",$rows);
    	return $this->JSON;
    }
    
    //创建一个新的用户
    public function addUser(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	 
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->addUser($params);
    	 
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    
    //根据用户ID查询用户信息
    public function getUserById(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	
    	$sysUserPage = new SysUserPage();
    	$userInfo = $sysUserPage->getUserById($params);
    	
    	$this->assign("userInfo",$userInfo);
    	return $this->JSON;
    }
    
    //修改用户信息
    public function updateUserInfo(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	 
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->updateUser($params);
    	 
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    
    //修改自己的个人信息
    public function updateSelfUserInfo(){
    	global $param,$userSession;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	$params['userId']=$userSession->getUserSession()["userId"];
    
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->updateUser($params);
    
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    
    //根据用户ID查询该用户的菜单权限信息
    public function queryMenusByUserId(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysMenuBusi.class.php');
    	 
    	$sysMenuBusi = new SysMenuBusi();
    	$userMenus = $sysMenuBusi->queryUserMenuList($params);
    
    	$this->assign("userMenus",$userMenus);
    	return $this->JSON;
    }
    
    //通过loginId查询用户信息
    public function checkLoginIdIsExsit(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->getUserByLoginId($params);
    	
    	if(count($result)>0)
    		$this->assign("result",0);
    	else 
    		$this->assign("result",1);
    	return $this->JSON;
    }
    
    //通过loginId查询用户信息
    public function checkLoginIdIsExsitOrActive(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    	 
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->getUserByLoginId($params);
    	 
    	if (count ( $result ) > 0) {
			if ($result ["userState"] != 4) {
				$this->assign ( "result", "success" );
			}else{
				$this->assign ( "result", "用户未激活" );
			}
		} else
			$this->assign ( "result", "用户未找到" );
		return $this->JSON;
    }
    
    //插入用户菜单集合
    public function addUserMenus(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysMenuBusi.class.php');
    
    	$sysMenuBusi = new SysMenuBusi();
    	$result = $sysMenuBusi->addUserMenus($params);
    	 
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    
    //插入用户角色集合
    public function addUserRoles(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserPage.class.php');
    
    	$sysUserPage = new SysUserPage();
    	$result = $sysUserPage->addUserRoles($params);
    
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    
    //查询所有角色信息以便选择
    public function queryRoles(){
    	global $param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysRolePage.class.php');
    	
    	$sysRolePage = new SysRolePage();
    	$roles = $sysRolePage->queryRoles($params);
    
    	$this->assign("roles",$roles);
    	return $this->JSON;
    }
}
?>